//const SUITS = ['red diam', 'red heart', 'black club', 'black spade'];
//const FACES = ['A', 'K', 'Q', 'J', '10', '9', '8', '7', '6', '5', '4', '3', '2'];

function combinationWeight(suits, faces)
{
	//Royal Flush
	if(royalFlush(suits, faces)) { 
		console.log(200);
		return 200;
	//Straight Flush
	} else if(straightFlush(suits, faces)) {		
		console.log(190);
		return 190;
	//Four of a Kind
	} else if(fourOfKind(suits, faces)) {
		console.log(180);
		return 180;
	//Full House
	} else if(fullHouse(suits, faces)) {
		console.log(170);
		return 170;
	//Flush 
	} else if(flush(suits, faces)) {
		console.log(160);
		return 160;
	//Straight 
	} else if(straight(suits, faces)) {
		console.log(150);
		return 150;
	//Three of a Kind 
	} else if(threeOfKind(suits, faces)) {
		console.log(140);
		return 140;
	//Two Pair
	} else if(twoPair(suits, faces)) {
		console.log(130);
		return 130;
	//One Pair
	} else if(onePair(suits, faces)) {
		console.log(120);
		return 120;
	// High Card
	} else {
		rank = highCard(suits, faces);
		console.log(rank);
		return rank;
	}
	
	
}

function royalFlush(suits, faces)
{
	return	arrayContains(faces,'A') && arrayContains(faces,'K') && arrayContains(faces,'Q') && arrayContains(faces,'J') && arrayContains(faces,'10') &&
			suits[faces.indexOf('A')] == suits[faces.indexOf('K')] &&
			suits[faces.indexOf('K')] == suits[faces.indexOf('Q')] &&
			suits[faces.indexOf('Q')] == suits[faces.indexOf('J')] &&
			suits[faces.indexOf('J')] == suits[faces.indexOf('10')];
}

function straightFlush(suits, faces) 
{
	var sameSuits = '';
	
	for(var i = 0; i < SUITS.length; i++) {
		suitsNum = 0;
		for(var ii = 0; ii < suits.length; ii++) {
			if(SUITS[i] == suits[ii]) {
				if(suitsNum == 4) {
					sameSuits = SUITS[i];
					break;
				}
				suitsNum++;
			}
		}
	}		

	if(sameSuits.length < 1) return false;
	
	var sameSuitFaces = [];
	for(var i = 0; i < suits.length; i++) {
		if(suits[i] == sameSuits) {
			addObjectToArray(sameSuitFaces, faces[i]); 
		}
	}

	return arrayContainsSubArray(FACES,sameSuitFaces, 5);
}

function fourOfKind(suits, faces) 
{
	for(var i = 0; i < FACES.length; i++) {
		facesNum = 0;
		for(var ii = 0; ii < faces.length; ii++) {
			if(FACES[i] == faces[ii]) {
				if(facesNum == 3) {
					return true;
				}
				facesNum++;
			}
		}
	}

	return false;	
}

function fullHouse(suits, faces) 
{
	var threeSameFaces = '';
	var twoSameFaces = '';
	
	for(var i = 0; i < FACES.length; i++) {
		facesNum = 0;
		for(var ii = 0; ii < faces.length; ii++) {
			if(FACES[i] == faces[ii]) {
				if(facesNum == 2) {
					threeSameFaces = FACES[i];
					break;
				}
				facesNum++;
			}
		}
	}

	if(threeSameFaces.length < 1) return false;	
	
	for(var i = 0; i < FACES.length; i++) {
		facesNum = 0;
		for(var ii = 0; ii < faces.length; ii++) {
			if(FACES[i] == faces[ii] && threeSameFaces != faces[ii]) {
				if(facesNum == 1) {
					twoSameFaces = FACES[i];
					break;
				}
				facesNum++;
			}
		}
	}
	
	return twoSameFaces.length < 1 ? false : true;
}

function flush(suits, faces) 
{
	for(var i = 0; i < SUITS.length; i++) {
		suitsNum = 0;
		for(var ii = 0; ii < suits.length; ii++) {
			if(SUITS[i] == suits[ii]) {
				if(suitsNum == 4) {
					return true;
				}
				suitsNum++;
			}
		}
	}
	
	return false;
}

function straight(suits, faces)
{
	return arrayContainsSubArray(FACES,faces, 5);
}

function threeOfKind(suits, faces) 
{
	for(var i = 0; i < FACES.length; i++) {
		facesNum = 0;
		for(var ii = 0; ii < faces.length; ii++) {
			if(FACES[i] == faces[ii]) {
				if(facesNum == 2) {
					return true;
				}
				facesNum++;
			}
		}
	}

	return false;	
}

function twoPair(suits, faces) 
{
	var twoSameFaces1 = '';
	var twoSameFaces2 = '';
	
	for(var i = 0; i < FACES.length; i++) {
		facesNum = 0;
		for(var ii = 0; ii < faces.length; ii++) {
			if(FACES[i] == faces[ii]) {
				if(facesNum == 1) {
					twoSameFaces1 = FACES[i];
					break;
				}
				facesNum++;
			}
		}
	}

	if(twoSameFaces1.length < 1) return false;	
	
	for(var i = 0; i < FACES.length; i++) {
		facesNum = 0;
		for(var ii = 0; ii < faces.length; ii++) {
			if(FACES[i] == faces[ii] && twoSameFaces1 != faces[ii]) {
				if(facesNum == 1) {
					twoSameFaces2 = FACES[i];
					break;
				}
				facesNum++;
			}
		}
	}
	
	return twoSameFaces2.length < 1 ? false : true;
}

function onePair(suits, faces) 
{
	var twoSameFaces = '';
	
	for(var i = 0; i < FACES.length; i++) {
		facesNum = 0;
		for(var ii = 0; ii < faces.length; ii++) {
			if(FACES[i] == faces[ii]) {
				if(facesNum == 1) {
					twoSameFaces = FACES[i];
					break;
				}
				facesNum++;
			}
		}
	}

	return (twoSameFaces.length < 1) ? false : true;	
}

function highCard(suits, faces) 
{	
	facesNum = 0;
	
	for(var i = 0; i < FACES.length; i++) {
		for(var ii = 0; ii < faces.length; ii++) {
			if(FACES[i] == faces[ii]) {
				return 13 - i;
			}
		}
	}
}









